/**
 * 
 */
package es.cloudcast.persistence.jdo.action.basic;

import javax.jdo.PersistenceManager;

import es.cloudcast.persistence.PersistenceException;
import es.cloudcast.persistence.dao.jdo.PersistenceManagerFactory;
import es.cloudcast.persistence.jdo.action.Action;

/**
 * Deletes given instance from the underlying datastore 
 * 
 * @author Samuel García Martínez <in0de>
 *
 */
public class DeleteAction implements Action {

	protected Object instance;
	
	public DeleteAction(Object instance) {
		this.instance = instance;
	}
	
	/* (non-Javadoc)
	 * @see es.cloudcast.persistence.jdo.action.Action#process(es.cloudcast.persistence.jdo.PersistenceManagerFactory)
	 */
	public Object process(PersistenceManagerFactory PMF)
			throws PersistenceException {
		PersistenceManager pManager = PMF.getCurrentPersistenceManager();
		
		try {
			pManager.deletePersistent(instance);
		} catch(Exception ex) {
			throw new PersistenceException(ex);
		}	
		
		return null;
	}

}
